package com.example.lancooznbk.view.widget;

import android.app.Activity;
import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.example.lancooznbk.R;
import com.hmy.popwindow.PopWindow;

/**
 * Created by Administrator on 2018\1\19 0019.
 */

public class DisciplinePopWindow extends PopupWindow {

    private View mMenuView;

    private ClickListenerInterface clickListenerInterface;

    private TextView mTvDisChinese;
    private TextView mTvDisMathematics;
    private TextView mTvDisEnglish;
    private TextView mTvDisChemical;
    private TextView mTvDisPhysical;
    private TextView mTvDisBiological;
    private TextView mTvDisGeographic;
    private TextView mTvDisHistory;
    private TextView mTvDisPolitical;

    private TextView mTvDisNameA;

    public interface ClickListenerInterface {
        public void doChangeSubject(String subjectName);
    }


    public DisciplinePopWindow(final Activity context, TextView mTv, ImageView mIv, View mView){
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.layout_discipline_window, null);

        new PopWindow.Builder(context)
                .setStyle(PopWindow.PopWindowStyle.PopDown)
                .setView(mMenuView)
                .setControlViewAnim(mIv, R.anim.btn_rotate_anim_1, R.anim.btn_rotate_anim_2, true)
                .show(mView);

        mTvDisNameA = mTv;

        initView();
    }

    private void initView(){
        mTvDisChinese = (TextView) mMenuView.findViewById(R.id.tv_chinese);
        mTvDisMathematics = (TextView) mMenuView.findViewById(R.id.tv_mathematics);
        mTvDisEnglish = (TextView) mMenuView.findViewById(R.id.tv_english);
        mTvDisChemical = (TextView) mMenuView.findViewById(R.id.tv_chemical);
        mTvDisPhysical = (TextView) mMenuView.findViewById(R.id.tv_physical);
        mTvDisBiological = (TextView) mMenuView.findViewById(R.id.tv_biological);
        mTvDisGeographic = (TextView) mMenuView.findViewById(R.id.tv_geographic);
        mTvDisHistory = (TextView) mMenuView.findViewById(R.id.tv_history);
        mTvDisPolitical = (TextView) mMenuView.findViewById(R.id.tv_political);

        clickChinese();
        mTvDisChinese.setOnClickListener(new clickListener());
        clickMathematics();
        clickEnglish();
        clickChemical();
        clickPhysical();
        clickBiological();
        clickGeographic();
        clickHistory();
        clickPolitical();

    }

    public void setClicklistener(ClickListenerInterface clickListenerInterface) {
        this.clickListenerInterface = clickListenerInterface;
    }

    private class clickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            int id = v.getId();
            switch (id) {
                case R.id.tv_chinese:
                    System.out.println("------long-------cancle cancle  cancle--222--------------");
                    clickListenerInterface.doChangeSubject(mTvDisChinese.getText().toString());
                    break;

                default:
                    System.out.println("-----ooooooo11111defalt----------------");
                    break;
            }
        }

    };

    /*
    * 语文
    * */
    private void clickChinese(){
        mTvDisChinese.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTvDisNameA.setText(mTvDisChinese.getText());
            }
        });

    }

    /*
    * 数学
    * */
    private void clickMathematics(){
        mTvDisMathematics.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTvDisNameA.setText(mTvDisMathematics.getText());
            }
        });

    }

    /*
    * 英语
    * */
    private void clickEnglish(){
        mTvDisEnglish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTvDisNameA.setText(mTvDisEnglish.getText());
            }
        });

    }

    /*
    * 化学
    * */
    private void clickChemical(){
        mTvDisChemical.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTvDisNameA.setText(mTvDisChemical.getText());
            }
        });

    }

    /*
    * 物理
    * */
    private void clickBiological(){
        mTvDisBiological.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTvDisNameA.setText(mTvDisBiological.getText());
            }
        });

    }

    /*
    * 生物
    * */
    private void clickPhysical(){
        mTvDisPhysical.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTvDisNameA.setText(mTvDisPhysical.getText());
            }
        });

    }

    /*
    * 地理
    * */
    private void clickGeographic(){
        mTvDisGeographic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTvDisNameA.setText(mTvDisGeographic.getText());
            }
        });

    }

    /*
    * 历史
    * */
    private void clickHistory(){
        mTvDisHistory.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTvDisNameA.setText(mTvDisHistory.getText());
            }
        });

    }

    /*
    * 政治
    * */
    private void clickPolitical(){
        mTvDisPolitical.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTvDisNameA.setText(mTvDisPolitical.getText());
            }
        });

    }


}
